package de.iritgo.skillfull.director.attacktype;

import de.iritgo.skillfull.director.AttackStrategy;
import de.iritgo.skillfull.director.AttackType;
import de.iritgo.skillfull.entity.Entity;

public class HardAttack extends AbstractAttack implements AttackType 
{
	public HardAttack(AttackStrategy attackStrategy) 
	{
		super (attackStrategy);
	}

	public int attackBottom (int heroHealth, int enemies, int timeLeft) 
	{
		checkStrategy (heroHealth, enemies, timeLeft);
		
		int y = 1024 + 32, moves = 5;
		
		for (int x = 0; x < 17 ; ++x)
		{
			int start = generator.nextInt (40);
			createEnemy ("alien1", x * (32 + start), y, moves, Entity.DST_FIELD.NORTH);
		}

		return 17;
	}

	public int attackLeft (int heroHealth, int enemies, int timeLeft) 
	{
		checkStrategy (heroHealth, enemies, timeLeft);

		int x = -32, moves = 5;
		
		for (int y = 0; y < 14 ; ++y)
		{
			int start = generator.nextInt (40);
			createEnemy ("alien1", x, y * (32 + start), moves, Entity.DST_FIELD.EAST);
		}

		return 14;
	}

	public int attackRight (int heroHealth, int enemies, int timeLeft) 
	{
		checkStrategy (heroHealth, enemies, timeLeft);

		int x = 1280 + 32, moves = 5;
		
		for (int y = 0; y < 13 ; ++y)
		{
			int start = generator.nextInt (40);
			createEnemy ("alien1", x, y * (32 + start), moves, Entity.DST_FIELD.WEST);
		}

		return 13;
	}

	public int attackTop (int heroHealth, int enemies, int timeLeft) 
	{
		checkStrategy (heroHealth, enemies, timeLeft);

		int y = 0 - 32, moves = 5;
		
		for (int x = 0; x < 17 ; ++x)
		{
			int start = generator.nextInt (40);
			createEnemy ("alien1", x * (32 + start), y, moves, Entity.DST_FIELD.SOUTH);
		}

		return 17;
	}
	
	private void checkStrategy (int heroHealth, int enemies, int timeLeft) 
	{
		if (enemies > 50)
		{
			// Ok that is to hard for the hero...shutdown to the low attack ;)!
			attackStrategy.setAttackType (attackStrategy.getLowAttack ());
		}
		if (enemies < 8 && timeLeft < 1000 * 60 * 2.5)
		{
			// Make it better
			attackStrategy.setAttackType (attackStrategy.getLowAttackWithSpeeder ());
		}
		if (timeLeft < 1000 * 30)
			attackStrategy.setAttackType (attackStrategy.getEndgameAttackWithSpeeder ());
			

	}
}
